﻿using System.Text.Json;
using TheSalLab.GeneralReturnValues;

ServiceResult FunctionThatSuccess() {
    return ServiceResult.CreateSuccessResult();
}

ServiceResult FunctionThatEncountersAnException() {
    var e = new Exception();
    return ServiceResult.CreateExceptionResult(e, e.Message);
}

ServiceResult<int> FunctionThatReturnsAnInt() {
    return ServiceResult<int>.CreateSuccessResult(256);
}

ServiceResultViewModel FunctionThatReturnsAServiceResultViewModel() {
    return ServiceResult.CreateSuccessResult().ToServiceResultViewModel();
}

void ServiceResultViewModelCanBeSerializedAndDeserialized() {
    var e = new Exception();
    var serviceResult = ServiceResult.CreateExceptionResult(e, e.Message);
    var json =
        JsonSerializer.Serialize(serviceResult.ToServiceResultViewModel());

    var serviceResultViewModel = JsonSerializer
        .Deserialize<ServiceResultViewModel>(json);
    serviceResult = serviceResultViewModel.ToServiceResult();
}

Console.WriteLine("Hello World!");